import argparse
import re

# construct the argument parser and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--input", required=True, help="path to iBug 300-W data split XML file")
ap.add_argument("-t", "--output", required=True, help="path output data split XML file")
args = vars(ap.parse_args())

LANDMARKS = set(list(range(36, 48)))

PART = re.compile("part name='[0-9]+'")

print("[INFO] parsing data split XML file...")
rows = open(args["input"]).read().strip().split("\n")
output = open(args["output"], "w")

# loop over the rows of the data split file
for row in rows:

	parts = re.findall(PART, row)
	if len(parts) == 0:
		output.write("{}\n".format(row))  #没匹配到则写入到文件中
	else:
		attr = "name='"
		i = row.find(attr)
		j = row.find("'", i + len(attr) + 1)
		name = int(row[i + len(attr):j])

		if name in LANDMARKS:
			output.write("{}\n".format(row))

output.close()